package org.pentaho.di.ui.trans.step;

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;

import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.*;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.ObjectLocationSpecificationMethod;
import org.pentaho.di.core.SwtUniversalImage;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.di.core.extension.ExtensionPointHandler;
import org.pentaho.di.core.extension.KettleExtensionPoint;
import org.pentaho.di.core.gui.Point;
import org.pentaho.di.core.plugins.PluginInterface;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.plugins.StepPluginType;
import org.pentaho.di.core.row.value.ValueMetaFactory;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.shared.SharedObjects;
import org.pentaho.di.trans.StepWithMappingMeta;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.steps.recordsfromstream.RecordsFromStreamMeta;
import org.pentaho.di.trans.streaming.common.BaseStreamStepMeta;
import org.pentaho.di.ui.core.FormDataBuilder;
import org.pentaho.di.ui.core.dialog.ErrorDialog;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.core.widget.ComboVar;
import org.pentaho.di.ui.core.widget.TableView;
import org.pentaho.di.ui.core.widget.TextVar;
import org.pentaho.di.ui.core.widget.VFSFileSelection;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.spoon.dialog.NewSubtransDialog;
import org.pentaho.xul.swt.tab.TabItem;
import org.pentaho.xul.swt.tab.TabSet;

public abstract class BaseStreamingDialog extends BaseStepDialog implements StepDialogInterface {
    public static final int INPUT_WIDTH = 350;
    private static final Class<?> PKG = BaseStreamingDialog.class;
    protected BaseStreamStepMeta meta;
    private Spoon spoonInstance;
    protected Label wlTransPath;
    protected VFSFileSelection wFileSection;
    protected Button wbCreateSubtrans;
    protected Label wlSubStep;
    protected ComboVar wSubStep;
    protected ObjectId referenceObjectId;
    protected ObjectLocationSpecificationMethod specificationMethod;
    protected ModifyListener lsMod;
    protected Label wlBatchSize;
    protected TextVar wBatchSize;
    protected TextVar wPrefetchCount;
    protected Label wlBatchDuration;
    protected TextVar wBatchDuration;
    protected TextVar wParallelism;
    protected CTabFolder wTabFolder;
    protected CTabItem wSetupTab;
    protected CTabItem wBatchTab;
    protected CTabItem wResultsTab;
    protected Composite wSetupComp;
    protected Composite wBatchComp;
    protected Composite wResultsComp;
    protected TableView fieldsTable;

    public BaseStreamingDialog(Shell parent, Object in, TransMeta tr, String sname) {
        super(parent, (BaseStepMeta)in, tr, sname);
        this.meta = (BaseStreamStepMeta)in;
        this.spoonInstance = Spoon.getInstance();
    }

    public String open() {
        Shell parent = this.getParent();
        Display display = parent.getDisplay();
        this.shell = new Shell(parent, 3312);
        this.props.setLook(this.shell);
        this.setShellImage(this.shell, this.meta);
        this.shell.setMinimumSize(527, 622);
        this.lsMod = (e) -> {
            this.meta.setChanged();
        };
        this.changed = this.meta.hasChanged();
        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = 15;
        formLayout.marginHeight = 15;
        this.shell.setLayout(formLayout);
        this.shell.setText(this.getDialogTitle());
        Label wicon = new Label(this.shell, 131072);
        wicon.setImage(this.getImage());
        FormData fdlicon = new FormData();
        fdlicon.top = new FormAttachment(0, 0);
        fdlicon.right = new FormAttachment(100, 0);
        wicon.setLayoutData(fdlicon);
        this.props.setLook(wicon);
        this.wlStepname = new Label(this.shell, 131072);
        this.wlStepname.setText("步骤名称:");
        this.props.setLook(this.wlStepname);
        this.fdlStepname = new FormData();
        this.fdlStepname.left = new FormAttachment(0, 0);
        this.fdlStepname.top = new FormAttachment(0, 0);
        this.wlStepname.setLayoutData(this.fdlStepname);
        this.wStepname = new Text(this.shell, 18436);
        this.wStepname.setText(this.stepname);
        this.props.setLook(this.wStepname);
        this.wStepname.addModifyListener(this.lsMod);
        this.fdStepname = new FormData();
        this.fdStepname.width = 250;
        this.fdStepname.left = new FormAttachment(0, 0);
        this.fdStepname.top = new FormAttachment(this.wlStepname, 5);
        this.wStepname.setLayoutData(this.fdStepname);
        Label spacer = new Label(this.shell, 258);
        this.props.setLook(spacer);
        FormData fdSpacer = new FormData();
        fdSpacer.height = 2;
        fdSpacer.left = new FormAttachment(0, 0);
        fdSpacer.top = new FormAttachment(this.wStepname, 15);
        fdSpacer.right = new FormAttachment(100, 0);
        fdSpacer.width = 497;
        spacer.setLayoutData(fdSpacer);
        this.wlTransPath = new Label(this.shell, 16384);
        this.props.setLook(this.wlTransPath);
        this.wlTransPath.setText("转换");
        FormData fdlTransPath = new FormData();
        fdlTransPath.left = new FormAttachment(0, 0);
        fdlTransPath.top = new FormAttachment(spacer, 15);
        fdlTransPath.right = new FormAttachment(50, 0);
        this.wlTransPath.setLayoutData(fdlTransPath);
        this.wFileSection = new VFSFileSelection(this.shell, 4, Const.STRING_TRANS_FILTER_EXT,
            Const.getTransformationFilterNames(), this.transMeta, this.repository);
        this.props.setLook(this.wFileSection);
        FormData fdFileSelection = new FormData();
        fdFileSelection.left = new FormAttachment(0, 0);
        fdFileSelection.top = new FormAttachment(this.wlTransPath, 5);
        this.wFileSection.setLayoutData(fdFileSelection);
        this.wbCreateSubtrans = new Button(this.shell, 8);
        this.props.setLook(this.wbCreateSubtrans);
        this.wbCreateSubtrans.setText("新建");
        FormData fdCreateSubtrans = new FormData();
        fdCreateSubtrans.left = new FormAttachment(this.wFileSection, 5);
        fdCreateSubtrans.top = new FormAttachment(this.wFileSection, 0, 128);
        this.wbCreateSubtrans.setLayoutData(fdCreateSubtrans);
        this.wbCreateSubtrans.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                BaseStreamingDialog.this.createNewSubtrans();
            }
        });
        this.wTabFolder = new CTabFolder(this.shell, 2048);
        this.props.setLook(this.wTabFolder, 5);
        this.wTabFolder.setSimple(false);
        this.wTabFolder.setUnselectedCloseVisible(true);
        this.wCancel = new Button(this.shell, 8);
        this.wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel", new String[0]));
        FormData fdCancel = new FormData();
        fdCancel.right = new FormAttachment(100, 0);
        fdCancel.bottom = new FormAttachment(100, 0);
        this.wCancel.setLayoutData(fdCancel);
        this.wOK = new Button(this.shell, 8);
        this.wOK.setText(BaseMessages.getString(PKG, "System.Button.OK", new String[0]));
        FormData fdOk = new FormData();
        fdOk.right = new FormAttachment(this.wCancel, -5);
        fdOk.bottom = new FormAttachment(100, 0);
        this.wOK.setLayoutData(fdOk);
        Label hSpacer = new Label(this.shell, 258);
        this.props.setLook(hSpacer);
        FormData fdhSpacer = new FormData();
        fdhSpacer.height = 2;
        fdhSpacer.left = new FormAttachment(0, 0);
        fdhSpacer.bottom = new FormAttachment(this.wCancel, -15);
        fdhSpacer.right = new FormAttachment(100, 0);
        hSpacer.setLayoutData(fdhSpacer);
        FormData fdTabFolder = new FormData();
        fdTabFolder.left = new FormAttachment(0, 0);
        fdTabFolder.top = new FormAttachment(this.wFileSection, 15);
        fdTabFolder.bottom = new FormAttachment(hSpacer, -15);
        fdTabFolder.right = new FormAttachment(100, 0);
        this.wTabFolder.setLayoutData(fdTabFolder);
        this.buildSetupTab();
        this.buildBatchTab();
        this.buildResultsTab();
        this.createAdditionalTabs();
        this.lsCancel = (e) -> {
            this.cancel();
        };
        this.lsOK = (e) -> {
            this.ok();
        };
        this.wOK.addListener(13, this.lsOK);
        this.wCancel.addListener(13, this.lsCancel);
        this.lsDef = new SelectionAdapter() {
            public void widgetDefaultSelected(SelectionEvent e) {
                BaseStreamingDialog.this.ok();
            }
        };
        this.wStepname.addSelectionListener(this.lsDef);
        this.shell.addShellListener(new ShellAdapter() {
            public void shellClosed(ShellEvent e) {
                BaseStreamingDialog.this.cancel();
            }
        });
        this.getData();
        this.setSize();
        this.wTabFolder.setSelection(0);
        this.wStepname.selectAll();
        this.wStepname.setFocus();
        this.shell.open();

        while (!this.shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }

        return this.stepname;
    }

    protected abstract String getDialogTitle();

    private void buildSetupTab() {
        this.wSetupTab = new CTabItem(this.wTabFolder, 0);
        this.wSetupTab.setText("设置");
        this.wSetupComp = new Composite(this.wTabFolder, 0);
        this.props.setLook(this.wSetupComp);
        FormLayout setupLayout = new FormLayout();
        setupLayout.marginHeight = 15;
        setupLayout.marginWidth = 15;
        this.wSetupComp.setLayout(setupLayout);
        this.buildSetup(this.wSetupComp);
        FormData fdSetupComp = new FormData();
        fdSetupComp.left = new FormAttachment(0, 0);
        fdSetupComp.top = new FormAttachment(0, 0);
        fdSetupComp.right = new FormAttachment(100, 0);
        fdSetupComp.bottom = new FormAttachment(100, 0);
        this.wSetupComp.setLayoutData(fdSetupComp);
        this.wSetupComp.layout();
        this.wSetupTab.setControl(this.wSetupComp);
    }

    protected abstract void buildSetup(Composite var1);

    protected void createAdditionalTabs() {}

    protected void createNewSubtrans() {
        TransMeta newSubTransMeta = this.createSubTransMeta();
        boolean saved = false;
        String path = null;
        if (this.spoonInstance.getRepository() != null) {
            try {
                saved = this.spoonInstance.saveToRepository(newSubTransMeta);
                path = this.getRepositoryRelativePath(newSubTransMeta.getPathAndName());
            } catch (KettleException var6) {
                new ErrorDialog(this.shell,
                    BaseMessages.getString(PKG, "BaseStreamingDialog.File.Save.Fail.Title", new String[0]),
                    BaseMessages.getString(PKG, "BaseStreamingDialog.File.Save.Fail.Message", new String[0]), var6);
            }
        } else {
            saved = this.spoonInstance.saveXMLFile(newSubTransMeta, false);
            if (saved) {
                try {
                    path = this.getRelativePath(KettleVFS.getFileObject(newSubTransMeta.getFilename()).toString());
                } catch (KettleFileException var5) {
                    new ErrorDialog(this.shell,
                        BaseMessages.getString(PKG, "BaseStreamingDialog.File.Save.Fail.Title", new String[0]),
                        BaseMessages.getString(PKG, "BaseStreamingDialog.File.Save.Fail.Message", new String[0]), var5);
                }
            }
        }

        if (saved && null != path) {
            this.wFileSection.wFileName.setText(path);
            this.createSubtrans(newSubTransMeta);
            if (this.props.showNewSubtransPopup()) {
                NewSubtransDialog newSubtransDialog = new NewSubtransDialog(this.shell, 0);
                this.props.setShowNewSubtransPopup(!newSubtransDialog.open());
            }
        }

    }

    protected TransMeta createSubTransMeta() {
        RecordsFromStreamMeta rm = new RecordsFromStreamMeta();
        String[] fieldNames = this.getFieldNames();
        int[] empty = new int[fieldNames.length];
        Arrays.fill(empty, -1);
        rm.setFieldname(fieldNames);
        rm.setType(this.getFieldTypes());
        rm.setLength(empty);
        rm.setPrecision(empty);
        StepMeta recsFromStream = new StepMeta("RecordsFromStream", "Get records from stream", rm);
        recsFromStream.setLocation(new Point(100, 100));
        recsFromStream.setDraw(true);
        TransMeta transMeta = new TransMeta();
        transMeta.addStep(recsFromStream);
        transMeta.setFilename("");
        return transMeta;
    }

    protected TableView getFieldsTable() {
        return this.fieldsTable;
    }

    protected String[] getFieldNames() {
        return (String[])Arrays.stream(this.getFieldsTable().getTable().getItems()).map((row) -> {
            return row.getText(2);
        }).toArray((x$0) -> {
            return new String[x$0];
        });
    }

    protected int[] getFieldTypes() {
        return Arrays.stream(this.getFieldsTable().getTable().getItems()).mapToInt((row) -> {
            return ValueMetaFactory.getIdForValueMeta(row.getText(3));
        }).toArray();
    }

    private void createSubtrans(TransMeta newTransMeta) {
        TabItem tabItem = this.spoonInstance.getTabSet().getSelected();
        newTransMeta.setMetaStore(this.spoonInstance.getMetaStore());

        try {
            SharedObjects sharedObjects = newTransMeta.readSharedObjects();
            newTransMeta.setSharedObjects(sharedObjects);
            newTransMeta.importFromMetaStore();
            newTransMeta.clearChanged();
        } catch (Exception var5) {
            this.log.logError("Failed to retrieve shared objects", var5);
        }

        this.spoonInstance.delegates.tabs.makeTabName(newTransMeta, false);
        this.spoonInstance.addTransGraph(newTransMeta);
        this.spoonInstance.applyVariables();
        if (this.spoonInstance.setDesignMode()) {
            this.spoonInstance.refreshViewTree();
        }

        this.spoonInstance.loadPerspective("001-spoon-jobs");

        try {
            ExtensionPointHandler.callExtensionPoint(this.log, KettleExtensionPoint.TransformationCreateNew.id,
                newTransMeta);
        } catch (KettleException var4) {
            this.log.logError("Failed to call extension point", var4);
        }

        TabSet ts = this.spoonInstance.getTabSet();
        ts.setSelected(tabItem);
    }

    private void buildBatchTab() {
        this.wBatchTab = new CTabItem(this.wTabFolder, 0);
        this.wBatchTab.setText("批次");
        this.wBatchComp = new Composite(this.wTabFolder, 0);
        this.props.setLook(this.wBatchComp);
        FormLayout batchLayout = new FormLayout();
        batchLayout.marginHeight = 15;
        batchLayout.marginWidth = 15;
        this.wBatchComp.setLayout(batchLayout);
        FormData fdBatchComp = new FormData();
        fdBatchComp.left = new FormAttachment(0, 0);
        fdBatchComp.top = new FormAttachment(0, 0);
        fdBatchComp.right = new FormAttachment(100, 0);
        fdBatchComp.bottom = new FormAttachment(100, 0);
        this.wBatchComp.setLayoutData(fdBatchComp);
        this.wlBatchDuration = new Label(this.wBatchComp, 16384);
        this.props.setLook(this.wlBatchDuration);
        this.wlBatchDuration.setText("批处理时间");
        FormData fdlBatchDuration = new FormData();
        fdlBatchDuration.left = new FormAttachment(0, 0);
        fdlBatchDuration.top = new FormAttachment(0, 0);
        fdlBatchDuration.right = new FormAttachment(50, 0);
        this.wlBatchDuration.setLayoutData(fdlBatchDuration);
        this.wBatchDuration = new TextVar(this.transMeta, this.wBatchComp, 18436);
        this.props.setLook(this.wBatchDuration);
        this.wBatchDuration.addModifyListener(this.lsMod);
        FormData fdBatchDuration = new FormData();
        fdBatchDuration.left = new FormAttachment(0, 0);
        fdBatchDuration.top = new FormAttachment(this.wlBatchDuration, 5);
        fdBatchDuration.width = 75;
        this.wBatchDuration.setLayoutData(fdBatchDuration);
        this.wlBatchSize = new Label(this.wBatchComp, 16384);
        this.props.setLook(this.wlBatchSize);
        this.wlBatchSize.setText("批处理大小");
        FormData fdlBatchSize = new FormData();
        fdlBatchSize.left = new FormAttachment(0, 0);
        fdlBatchSize.top = new FormAttachment(this.wBatchDuration, 10);
        fdlBatchSize.right = new FormAttachment(50, 0);
        this.wlBatchSize.setLayoutData(fdlBatchSize);
        this.wBatchSize = new TextVar(this.transMeta, this.wBatchComp, 18436);
        this.props.setLook(this.wBatchSize);
        this.wBatchSize.addModifyListener(this.lsMod);
        FormData fdBatchSize = new FormData();
        fdBatchSize.left = new FormAttachment(0, 0);
        fdBatchSize.top = new FormAttachment(this.wlBatchSize, 5);
        fdBatchSize.width = 75;
        this.wBatchSize.setLayoutData(fdBatchSize);
        Label wlParallelism = new Label(this.wBatchComp, 16384);
        this.props.setLook(wlParallelism);
        wlParallelism.setText("并行型");
        wlParallelism.setLayoutData((new FormDataBuilder()).left().top(this.wBatchSize, 10).right(50, 0).result());
        this.wParallelism = new TextVar(this.transMeta, this.wBatchComp, 18436);
        this.props.setLook(this.wParallelism);
        this.wParallelism.addModifyListener(this.lsMod);
        this.wParallelism.setLayoutData((new FormDataBuilder()).left().top(wlParallelism, 5).width(75).result());
        Label wlPrefetchCount = new Label(this.wBatchComp, 16384);
        this.props.setLook(wlPrefetchCount);
        wlPrefetchCount.setText("预先载入数");
        wlPrefetchCount.setLayoutData((new FormDataBuilder()).left().top(this.wParallelism, 10).right(50, 0).result());
        this.wPrefetchCount = new TextVar(this.transMeta, this.wBatchComp, 18436);
        this.props.setLook(this.wPrefetchCount);
        this.wPrefetchCount.addModifyListener(this.lsMod);
        this.wPrefetchCount.setLayoutData((new FormDataBuilder()).left().top(wlPrefetchCount, 5).width(125).result());
        this.wBatchComp.layout();
        this.wBatchTab.setControl(this.wBatchComp);
    }

    private void buildResultsTab() {
        this.wResultsTab = new CTabItem(this.wTabFolder, 0);
        this.wResultsTab.setText("结果字段");
        this.wResultsComp = new Composite(this.wTabFolder, 0);
        this.props.setLook(this.wResultsComp);
        FormLayout resultsLayout = new FormLayout();
        resultsLayout.marginHeight = 15;
        resultsLayout.marginWidth = 15;
        this.wResultsComp.setLayout(resultsLayout);
        FormData fdResultsComp = new FormData();
        fdResultsComp.left = new FormAttachment(0, 0);
        fdResultsComp.top = new FormAttachment(0, 0);
        fdResultsComp.right = new FormAttachment(100, 0);
        fdResultsComp.bottom = new FormAttachment(100, 0);
        this.wResultsComp.setLayoutData(fdResultsComp);
        this.wlSubStep = new Label(this.wResultsComp, 16384);
        this.props.setLook(this.wlSubStep);
        FormData fdlSubTrans = new FormData();
        fdlSubTrans.left = new FormAttachment(0, 0);
        fdlSubTrans.top = new FormAttachment(0, 0);
        this.wlSubStep.setLayoutData(fdlSubTrans);
        this.wlSubStep.setText("子转换步骤");
        this.wSubStep = new ComboVar(this.transMeta, this.wResultsComp, 18436);
        this.props.setLook(this.wSubStep);
        FormData fdSubStep = new FormData();
        fdSubStep.left = new FormAttachment(0, 0);
        fdSubStep.top = new FormAttachment(this.wlSubStep, 5);
        fdSubStep.width = 250;
        this.wSubStep.setLayoutData(fdSubStep);
        this.wSubStep.getCComboWidget().addListener(15, this::populateSubSteps);
        this.wResultsComp.layout();
        this.wResultsTab.setControl(this.wResultsComp);
    }

    protected void getData() {
        if (this.meta.getTransformationPath() != null) {
            this.wFileSection.wFileName.setText(this.meta.getTransformationPath());
        }

        if (this.meta.getBatchSize() != null) {
            this.wBatchSize.setText(this.meta.getBatchSize());
        }

        if (this.meta.getBatchDuration() != null) {
            this.wBatchDuration.setText(this.meta.getBatchDuration());
        }

        if (this.meta.getParallelism() != null) {
            this.wParallelism.setText(this.meta.getParallelism());
        }

        if (this.meta.getPrefetchCount() != null) {
            this.wPrefetchCount.setText(this.meta.getPrefetchCount());
        }

        if (this.meta.getSubStep() != null) {
            this.wSubStep.setText(this.meta.getSubStep());
        }

        this.specificationMethod = this.meta.getSpecificationMethod();
    }

    protected void populateSubSteps(Event event) {
        try {
            String current = this.wSubStep.getText();
            this.wSubStep.removeAll();
            Optional.ofNullable(this.getMappingMeta()).ifPresent((transMeta) -> {
                Stream var10000 = transMeta.getSteps().stream().map(StepMeta::getName).sorted();
                ComboVar var10001 = this.wSubStep;
                var10000.forEach(var10001::adds);
            });
            Display.getDefault().asyncExec(() -> {
                this.wSubStep.setText(current);
            });
        } catch (KettleException var3) {
            this.logDebug(var3.getMessage(), new Object[] {var3});
        }

    }

    private TransMeta getMappingMeta() throws KettleException {
        BaseStreamStepMeta baseMeta = (BaseStreamStepMeta)this.meta.clone();
        this.updateMeta(baseMeta);
        return StepWithMappingMeta.loadMappingMeta(baseMeta, this.getRepository(), this.getMetaStore(), this.transMeta);
    }

    private Image getImage() {
        PluginInterface plugin = PluginRegistry.getInstance().getPlugin(StepPluginType.class,
            this.stepMeta.getStepMetaInterface(), Const.DEFAULT_VERSION);
        String id = plugin.getId();
        return id != null ? ((SwtUniversalImage)GUIResource.getInstance().getImagesSteps().get(id))
            .getAsBitmapForSize(this.shell.getDisplay(), 48, 48) : null;
    }

    private void cancel() {
        this.meta.setChanged(false);
        this.dispose();
    }

    private void ok() {
        this.stepname = this.wStepname.getText();
        this.updateMeta(this.meta);
        this.dispose();
    }

    private void updateMeta(BaseStreamStepMeta streamMeta) {
        streamMeta.setTransformationPath(this.wFileSection.wFileName.getText());
        streamMeta.setBatchSize(this.wBatchSize.getText());
        streamMeta.setBatchDuration(this.wBatchDuration.getText());
        streamMeta.setParallelism(this.wParallelism.getText());
        streamMeta.setPrefetchCount(this.wPrefetchCount.getText());
        streamMeta.setSpecificationMethod(this.specificationMethod);
        streamMeta.setSubStep(this.wSubStep.getText());
        switch (this.specificationMethod) {
            case FILENAME:
                streamMeta.setFileName(this.wFileSection.wFileName.getText());
                streamMeta.setDirectoryPath((String)null);
                streamMeta.setTransName((String)null);
                streamMeta.setTransObjectId((ObjectId)null);
                break;
            case REPOSITORY_BY_NAME:
                String transPath = this.wFileSection.wFileName.getText();
                String transName = transPath;
                String directory = "";
                int index = transPath.lastIndexOf(47);
                if (index != -1) {
                    transName = transPath.substring(index + 1);
                    directory = transPath.substring(0, index);
                }

                streamMeta.setDirectoryPath(directory);
                streamMeta.setTransName(transName);
                streamMeta.setFileName((String)null);
                streamMeta.setTransObjectId((ObjectId)null);
        }

        this.additionalOks(streamMeta);
    }

    protected void additionalOks(BaseStreamStepMeta meta) {}

    protected String getRepositoryRelativePath(String path) {
        String parentPath = this.transMeta.getRepositoryDirectory().getPath();
        if (path.startsWith(parentPath)) {
            path = path.replace(parentPath, "${Internal.Entry.Current.Directory}");
        }
        return path;
    }

    protected String getRelativePath(String filePath) {
        String parentFolder = null;
        try {
            parentFolder = KettleVFS.getFileObject(this.transMeta.environmentSubstitute(this.transMeta.getFilename()))
                .getParent().toString();
        } catch (Exception var4) {
        }

        if (filePath != null && parentFolder != null && filePath.startsWith(parentFolder)) {
            filePath = filePath.replace(parentFolder, "${Internal.Entry.Current.Directory}");
        }

        return filePath;
    }
}
